package cn.gz.demo.ui;


import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;

import com.google.android.material.bottomsheet.BottomSheetBehavior;

import cn.gz.demo.R;
import cn.gz.demo.databinding.BottomSheetBinding;
import cn.gz.demo.ui.base.BaseActivity;
import cn.gz.demo.utils.DisplayUtil;

/**
 * @author Liuyz
 * @date 2020/6/1010:37
 */
public class BottomSheetActivity extends BaseActivity {
    private BottomSheetBinding binding;
    private BottomSheetBehavior behavior;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_bottom_sheet);

        behavior = BottomSheetBehavior.from(binding.bottomSheet);
        behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState) {
                //监听BottomSheet状态的改变
                if (newState == BottomSheetBehavior.STATE_DRAGGING) {
                    ViewGroup.LayoutParams params = bottomSheet.getLayoutParams();
                    params.height = DisplayUtil.dip2px(context, 450);
                    bottomSheet.setLayoutParams(params);
                }
            }

            @Override
            public void onSlide(@NonNull View bottomSheet, float slideOffset) {
                //监听拖拽中的回调，根据slideOffset可以做一些动画

            }
        });
    }
}
